package permission

import (
	"context"

	v1 "gitee.com/liangziyisheng/caas-platform-mc/api/permission/v1"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/service"
)

func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) {
	in := &v1.ListInput{}
	in.MenuId = req.MenuId
	out, err := service.Permission().List(ctx, in)
	if err != nil {
		return nil, err
	}
	res = &v1.ListRes{Total: out.Total, Data: make([]v1.Pms, 0)}
	for _, v := range out.Data {
		t := v1.Pms{
			Id:        v.Id,
			Name:      v.Name,
			Path:      v.Path,
			Operation: v.Operation,
		}
		res.Data = append(res.Data, t)
	}
	return res, nil
}
